* Import data from presidential elections 2022
import delimited "$raw/BPW22.csv", encoding(UTF-8) parselocale(en_AT) groupseparator(.) decimalseparator(,) clear

rename gebietsname municipality_name

* Generate municipality_id
replace gkz = subinstr(gkz,"G","",.)
destring gkz, generate(municipality_id) force
drop gkz

drop if municipality_id==. | municipality_id<10000 | municipality_id>=100000

* Merging Communities to Matrei am Brenner
expand 3 if municipality_id==70370 
sort municipality_id
by municipality_id: gen n=_n


recode municipality_id (70370 = 70327) if n==1 // Matrei am Brenner
recode municipality_id (70370 = 70330) if n==2  // Mühlbachl
recode municipality_id (70370 = 70341) if n==3  // Pfons

gen turnout = 100 * valid_votes/eligible_voters

keep municipality_id turnout sh_* 

save "$edited/bpw_2022", replace
